package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.OtherExpense;

public class OtherExpenseDAOImpl extends BaseHibernateDAOImpl<OtherExpense> implements OtherExpenseDAO {

	public OtherExpense getOtherExpenseByOtherExpenseID(String oeID) {
		OtherExpense otherExpense;
		try {
			otherExpense = (OtherExpense) getSession().get(OtherExpense.class, oeID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return otherExpense;
	}

	@SuppressWarnings("unchecked")
	public List<OtherExpense> getAllOtherExpenseByCondition(String hql) {
		List<OtherExpense> otherExpenses;
		try {
			Query query = getSession().createQuery("from OtherExpense" + hql);
			otherExpenses = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return otherExpenses;
	}

	@SuppressWarnings("unchecked")
	public List<OtherExpense> getAllOtherExpenseByConditionByPage(String hql, int currentPage, int lineSize) {
		List<OtherExpense> otherExpenses;
		try {
			Query query = getSession().createQuery("from OtherExpense" + hql);
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			otherExpenses = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return otherExpenses;
	}
}
